﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace NetOpen_System.Component
{
    /// <summary>
    /// Url匹配引擎
    /// </summary>
    public sealed class UrlMatchEngine
    {

        private List<SkipedUrl> m_UrlList = new List<SkipedUrl>();
       

        public UrlMatchEngine(XmlNode node)
        {
            ParseFromNode(node);
        }

        private void ParseFromNode(XmlNode node)
        {
            if (node == null || !node.HasChildNodes)
                return;

            foreach (XmlNode n in node.ChildNodes)
            {
                if (n.Name == "add")
                    AppendNode(n);
                

            }

        }

        private void AppendNode(XmlNode node)
        {
            XmlAttributeReader attReader = new XmlAttributeReader(node.Attributes);
            string ipcity = attReader.GetString("ipcity", "");
            string urlfrom = attReader.GetString("urlfrom", "");
            string urlto = attReader.GetString("urlto", "");
            string outkeyword = attReader.GetString("outkeyword", "");

            SkipedUrl skipurl = new SkipedUrl();
            skipurl.IpCity = ipcity;
            skipurl.UrlFrom = urlfrom;
            skipurl.UrlTo = urlto;
            skipurl.OutKeyWord = outkeyword;

            m_UrlList.Add(skipurl);
        }


        public List<SkipedUrl> UrlList
        {
            get { return m_UrlList; }
        }
    }
}
